package controllers;


import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.SolutionSubmission;
import models.RatingBest;
import models.Rating;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;


	public class BestOfBestConnect{
		
	int iROWS;
	Boolean hasEntries;
	public List<HashMap<String, Object>> getQuery(String fieldName, String Value) {
		List<HashMap<String, Object>> objList = new LinkedList<HashMap<String, Object>>();
		Objectify ofy1 = ObjectifyService.begin();
		
		try {
			
			Query<RatingBest> q = ofy1.query(RatingBest.class).filter(fieldName, Value).filter("isActive", true);
			for (RatingBest f : q.fetch()) {
				HashMap<String, Object> itemMap = new HashMap<String, Object>();				
				itemMap.put("solID", f.getSolID());
				itemMap.put("Quarter", f.getBestOfBestQuater());		
				long l = f.getSolID();			
				
				
				try{
					Objectify ofy2 = ObjectifyService.begin();
					Query<SolutionSubmission> a = ofy2.query(SolutionSubmission.class).filter("solID",l);
					for (SolutionSubmission fe : a.fetch()) {	
						itemMap.put("solCode", fe.getSolCode()); //ADDED BY KULPRAPAS SEP 27,2012 to get Solution Code
						itemMap.put("Title", fe.getTitle());
						itemMap.put("Location", fe.getLocation());
						itemMap.put("Customer", fe.getCustomer());
						itemMap.put("BenefitResult", fe.getAchievedTypeDesc());
						itemMap.put("Achieved", fe.getAnnProdSavings());
						hasEntries = true;
					}
				}catch (Exception e) {
					e.printStackTrace();
				}
				objList.add(itemMap);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return objList;
	}

}

		
